package com.tjtt.common.utils;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.struts2.ServletActionContext;

import com.tjtt.tdm.base.BaseAction;
import com.tjtt.tdm.base.PubMethod;


public class ExcelExportUtil extends BaseAction {

	/**
	 * @param excel_name
	 *            生成的Excel文件路径+名称
	 * @param headList
	 *            Excel文件Head标题集合
	 * @param field_list
	 *            Excel文件Field标题集合
	 * @param dataList
	 *            Excel文件数据内容部分
	 * @throws Exception
	 */
	public static void createExcel1(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList,String userName,Date createTime,List<String> fieldList2,List<Map<String, Object>> setList,String headName)
			throws Exception {
		// 创建新的Excel 工作簿
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 在Excel工作簿中建一工作表，其名为缺省值
		// 如要新建一名为"效益指标"的工作表，其语句为：
		// HSSFSheet sheet = workbook.createSheet("效益指标");
		HSSFSheet sheet0 = workbook.createSheet("汇总");
		HSSFSheet sheet = workbook.createSheet();
//---------------add--------- start1---------------------------------------------------------------------------------------
		// 设置字体     
		HSSFFont font = workbook.createFont();     
	    font.setFontName("黑体");     
	    font.setFontHeightInPoints((short) 10);  
	    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗  
	    
	    HSSFFont headfont1 = workbook.createFont();     
	    headfont1.setFontName("黑体");     
	    headfont1.setFontHeightInPoints((short) 12);// 字体大小     
	    headfont1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗  
	    
		HSSFFont headfont = workbook.createFont();     
	    headfont.setFontName("黑体");     
	    headfont.setFontHeightInPoints((short) 22);// 字体大小     
	    headfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗     
	    
	 // 另一个样式     
		HSSFCellStyle headstyle1 = workbook.createCellStyle();     
		headstyle1.setFont(headfont1);     
	    headstyle1.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
	    headstyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中     
	    headstyle1.setLocked(true);     
	    headstyle1.setWrapText(true);// 自动换行
		// 另一个样式     
		HSSFCellStyle headstyle = workbook.createCellStyle();     
		headstyle.setFont(headfont);     
	    headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
	    headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中     
	    headstyle.setLocked(true);     
	    headstyle.setWrapText(true);// 自动换行   
	    
	    // 另一个样式     
		HSSFCellStyle centerstyle = workbook.createCellStyle();     
		centerstyle.setFont(font);     
		//centerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
		centerstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中     
		centerstyle.setWrapText(false);     
		centerstyle.setLeftBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderLeft((short) 1);     
		centerstyle.setRightBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderRight((short) 1);     
		//centerstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 设置单元格的边框为粗体     
		centerstyle.setBottomBorderColor(HSSFColor.BLACK.index); // 设置单元格的边框颜色．     
		centerstyle.setFillForegroundColor(HSSFColor.WHITE.index);// 设置单元格的背景颜色．  
		/*第一个sheet*/
		HSSFRow row00 = sheet0.createRow(0); //第一个sheet的第一行 
		HSSFCell cell00 = row00.createCell(0);
		row00.setHeight((short) 460);  
		cell00.setCellValue(new HSSFRichTextString(headName));
		cell00.setCellStyle(headstyle1);  
		CellRangeAddress range1 = new CellRangeAddress(0, 0, 0, 4);     
        sheet0.addMergedRegion(range1);  
        HSSFRow row01 = sheet0.createRow(1);
        HSSFCell cell10 = row01.createCell(0);
        cell10.setCellValue(new HSSFRichTextString("序号"));
        HSSFCell cell11 = row01.createCell(1);
        cell11.setCellValue(new HSSFRichTextString("名称"));
        sheet0.setColumnWidth(1, 3766);
        HSSFCell cell12 = row01.createCell(2);
        cell12.setCellValue(new HSSFRichTextString("分级"));
        HSSFCell cell13 = row01.createCell(3);
        cell13.setCellValue(new HSSFRichTextString("数量"));
        //写入数据
        String str = "";
        for (int n = 0; n < setList.size(); n++) {
			// 在索引1的位置创建行（最顶端的行）
			HSSFRow row_value = sheet0.createRow(n + 2);
			Map<String, Object> dataMap1 = setList.get(n);
			// ===============================================================
			
			for (int i = 0; i < fieldList2.size(); i++) {

				// 在索引0的位置创建单元格（左上端）
				HSSFCell cell = row_value.createCell(i);
				// 定义单元格为字符串类型
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				// 在单元格中输入一些内容
				str=objToString(dataMap1.get(fieldList2.get(i)));
				if(DataTypeJudge(fieldList2.get(i))){
					cell.setCellValue(DataTypeToCN(fieldList2.get(i),dataMap1.get(fieldList2.get(i))));
					
//					sheet.addMergedRegion(new Region(i,(short)1,i,(short)2));// 四个参数分别是：起始行，起始列，结束行，结束列   

				}else{
					cell.setCellValue(objToString(dataMap1.get(fieldList2.get(i))));
				}
				
			}
        }
        /*第二个sheet*/
		HSSFRow row0 = sheet.createRow(0);   //第二个sheet的第一行  
		// 设置行高     
        row0.setHeight((short) 900);     
        // 创建第一列     
        HSSFCell cell0 = row0.createCell(0);     
        cell0.setCellValue(new HSSFRichTextString(excel_name.substring(0,(excel_name.lastIndexOf(".")))));     
        cell0.setCellStyle(headstyle);     
        /**   
         * 合并单元格   
         *    第一个参数：第一个单元格的行数（从0开始）   
         *    第二个参数：第二个单元格的行数（从0开始）   
         *    第三个参数：第一个单元格的列数（从0开始）   
         *    第四个参数：第二个单元格的列数（从0开始）   
         */     
        CellRangeAddress range = new CellRangeAddress(0, 0, 0, 7);     
        sheet.addMergedRegion(range);     
        // 创建第二行     
		HSSFRow row1 = sheet.createRow(1);     
		HSSFCell cell1 = row1.createCell(0); 
		
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd "); 
		String jointime = sdf.format(createTime);
		
		cell1.setCellValue("导出时间："+jointime);     
		cell1.setCellStyle(centerstyle);  
		// 第三行     
        HSSFRow row2 = sheet.createRow(2);     
        HSSFCell cell3 = row2.createCell(0);     
        cell3.setCellValue("导出人："+userName);     
        cell3.setCellStyle(centerstyle);     
		// 第4行     
        HSSFRow row3 = sheet.createRow(3);     
        HSSFCell cell2 = row3.createCell(0);     
        cell2.setCellValue("总条数："+dataList.size());     
        cell2.setCellStyle(centerstyle);     
//---------------add---start2---------------------------------------------------------------------------------------------		
		
//--------------add----end-----------------------------------------------------------------------------------------------		
		// 在索引0的位置创建行（最顶端的行）
		HSSFRow row = sheet.createRow(6);
		// ===============================================================
		for (int i = 0; i < headList.size(); i++) {

			// 在索引0的位置创建单元格（左上端）
			HSSFCell cell = row.createCell(i);
			// 定义单元格为字符串类型
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			// 在单元格中输入一些内容
			cell.setCellValue(headList.get(i));
		}
		// ===============================================================
		String str1;
		for (int n = 0; n < dataList.size(); n++) {
			// 在索引1的位置创建行（最顶端的行）
			HSSFRow row_value = sheet.createRow(n + 7);
			Map<String, Object> dataMap = dataList.get(n);
			// ===============================================================
			
			for (int i = 0; i < fieldList.size(); i++) {

				// 在索引0的位置创建单元格（左上端）
				HSSFCell cell = row_value.createCell(i);
				// 定义单元格为字符串类型
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				// 在单元格中输入一些内容
				str1=objToString(dataMap.get(fieldList.get(i)));
				if(DataTypeJudge(fieldList.get(i))){
					cell.setCellValue(DataTypeToCN(fieldList.get(i),dataMap.get(fieldList.get(i))));
					
//					sheet.addMergedRegion(new Region(i,(short)1,i,(short)2));// 四个参数分别是：起始行，起始列，结束行，结束列   

				}else{
					cell.setCellValue(objToString(dataMap.get(fieldList.get(i))));
				}
				
			}
			// ===============================================================
		}
		FileOutputStream fileOut = new FileOutputStream("c:/123.xls");
		workbook.write(fileOut);
        fileOut.close();
//		OutputStream output=null;
//		usegetResponse().setHeader("Content-Type", "application/octet-stream");
//		usegetResponse().addHeader("Content-Disposition", "attachment;filename="
//    		     + getDownloadChineseFileName(excel_name));
//        output = usegetResponse().getOutputStream();
//        workbook.write(output);
//        output.flush();
//        output.close();
	}
	 
	
	public static void createExcel(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList,String userName,Date createTime)
			throws Exception {
		// 创建新的Excel 工作簿
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 在Excel工作簿中建一工作表，其名为缺省值
		// 如要新建一名为"效益指标"的工作表，其语句为：
		// HSSFSheet sheet = workbook.createSheet("效益指标");
		HSSFSheet sheet = workbook.createSheet();
//---------------add--------- start1---------------------------------------------------------------------------------------
		// 设置字体     
		HSSFFont font = workbook.createFont();     
	    font.setFontName("黑体");     
	    font.setFontHeightInPoints((short) 10);  
	    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗  
	    
		HSSFFont headfont = workbook.createFont();     
	    headfont.setFontName("黑体");     
	    headfont.setFontHeightInPoints((short) 22);// 字体大小     
	    headfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗     
	    
		// 另一个样式     
		HSSFCellStyle headstyle = workbook.createCellStyle();     
		headstyle.setFont(headfont);     
	    headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
	    headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中     
	    headstyle.setLocked(true);     
	    headstyle.setWrapText(true);// 自动换行   
	    
	    // 另一个样式     
		HSSFCellStyle centerstyle = workbook.createCellStyle();     
		centerstyle.setFont(font);     
		//centerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
		centerstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中     
		centerstyle.setWrapText(false);     
		centerstyle.setLeftBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderLeft((short) 1);     
		centerstyle.setRightBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderRight((short) 1);     
		//centerstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 设置单元格的边框为粗体     
		centerstyle.setBottomBorderColor(HSSFColor.BLACK.index); // 设置单元格的边框颜色．     
		centerstyle.setFillForegroundColor(HSSFColor.WHITE.index);// 设置单元格的背景颜色．  
	
/*        第二个sheet
		HSSFRow row0 = sheet.createRow(0);   //第二个sheet的第一行  
		// 设置行高     
        row0.setHeight((short) 900);     
        // 创建第一列     
        HSSFCell cell0 = row0.createCell(0);     
        cell0.setCellValue(new HSSFRichTextString(excel_name.substring(0,(excel_name.lastIndexOf(".")))));     
        cell0.setCellStyle(headstyle);     
        *//**   
         * 合并单元格   
         *    第一个参数：第一个单元格的行数（从0开始）   
         *    第二个参数：第二个单元格的行数（从0开始）   
         *    第三个参数：第一个单元格的列数（从0开始）   
         *    第四个参数：第二个单元格的列数（从0开始）   
         *//*     
        CellRangeAddress range = new CellRangeAddress(0, 0, 0, 7);     
        sheet.addMergedRegion(range);     
        // 创建第二行     
		HSSFRow row1 = sheet.createRow(1);     
		HSSFCell cell1 = row1.createCell(0); 
		
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd "); 
		String jointime = sdf.format(createTime);
		
		cell1.setCellValue("导出时间："+jointime);     
		cell1.setCellStyle(centerstyle);  
		// 第三行     
        HSSFRow row2 = sheet.createRow(2);     
        HSSFCell cell3 = row2.createCell(0);     
        cell3.setCellValue("导出人："+userName);     
        cell3.setCellStyle(centerstyle);     
		// 第4行     
        HSSFRow row3 = sheet.createRow(3);     
        HSSFCell cell2 = row3.createCell(0);     
        cell2.setCellValue("总条数："+dataList.size());     
        cell2.setCellStyle(centerstyle);    */ 
//---------------add---start2---------------------------------------------------------------------------------------------		
		
//--------------add----end-----------------------------------------------------------------------------------------------		
		// 在索引0的位置创建行（最顶端的行）
		HSSFRow row = sheet.createRow(0);
		// ===============================================================
		for (int i = 0; i < headList.size(); i++) {

			// 在索引0的位置创建单元格（左上端）
			HSSFCell cell = row.createCell(i);
			// 定义单元格为字符串类型
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			// 在单元格中输入一些内容
			cell.setCellValue(headList.get(i));
		}
		// ===============================================================
		String str1;
		for (int n = 0; n < dataList.size(); n++) {
			// 在索引1的位置创建行（最顶端的行）
			HSSFRow row_value = sheet.createRow(n + 1);
			Map<String, Object> dataMap = dataList.get(n);
			// ===============================================================
			
			for (int i = 0; i < fieldList.size(); i++) {

				// 在索引0的位置创建单元格（左上端）
				HSSFCell cell = row_value.createCell(i);
				// 定义单元格为字符串类型
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				// 在单元格中输入一些内容
				str1=objToString(dataMap.get(fieldList.get(i)));
				if(DataTypeJudge(fieldList.get(i))){
					cell.setCellValue(DataTypeToCN(fieldList.get(i),dataMap.get(fieldList.get(i))));
					
//					sheet.addMergedRegion(new Region(i,(short)1,i,(short)2));// 四个参数分别是：起始行，起始列，结束行，结束列   

				}else{
					cell.setCellValue(objToString(dataMap.get(fieldList.get(i))));
				}
				
			}
			// ===============================================================
		}
		/**
		FileOutputStream fileOut = new FileOutputStream("c:/123.xls");
		workbook.write(fileOut);
        fileOut.close();
        */
		OutputStream output=null;
		usegetResponse().setHeader("Content-Type", "application/octet-stream");
		usegetResponse().addHeader("Content-Disposition", "attachment;filename="
    		     + getDownloadChineseFileName(excel_name));
        output = usegetResponse().getOutputStream();
        workbook.write(output);
        output.flush();
        output.close();
	}
	public static void createExcel2007(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList,String userName,Date createTime)
			throws Exception {
		XSSFWorkbook wb = new XSSFWorkbook();
		String filePath = "c:/cf/export/"+PubMethod.GetTimerName()+"/";
		File targetFile = new File(filePath);
		if ( ! (targetFile.exists())  &&   ! (targetFile.isDirectory()))  {
	        boolean  creadok  =  targetFile.mkdirs();
	        if (creadok)  {
	           System.out.println( " ok:创建文件夹成功！ " );
	       } else  {
	           System.out.println( " err:创建文件夹失败！ " ); 
	
	           
	       } 
	   } 
		filePath = filePath + excel_name;
		File targetFile1 = new File(filePath);
		if (targetFile1.exists()) {
			targetFile1.delete();
		} else {
			targetFile1.createNewFile();
		}
		FileOutputStream fileOut = new FileOutputStream(filePath);
		// 创建新的Excel 工作簿
		// 在Excel工作簿中建一工作表，其名为缺省值
		// 如要新建一名为"效益指标"的工作表，其语句为：
		// HSSFSheet sheet = workbook.createSheet("效益指标");
		XSSFSheet sheet = wb.createSheet();
		// 在索引0的位置创建行（最顶端的行）
		XSSFRow row = sheet.createRow(0);
		for (int i = 0; i < headList.size(); i++) {
			XSSFCell cell = row.createCell(i);
			cell.setCellType(XSSFCell.CELL_TYPE_STRING);
			cell.setCellValue(headList.get(i));
		}
//		String str1;
//		for (int n = 0; n < dataList.size(); n++) {
//			XSSFRow row_value = sheet.createRow(n + 1);
//			Map<String, Object> dataMap = dataList.get(n);
//			for (int i = 0; i < fieldList.size(); i++) {
//				XSSFCell cell = row_value.createCell(i);
//				cell.setCellType(XSSFCell.CELL_TYPE_STRING);
//				str1=objToString(dataMap.get(fieldList.get(i)));
//				if(DataTypeJudge(fieldList.get(i))){
//					cell.setCellValue(DataTypeToCN(fieldList.get(i),dataMap.get(fieldList.get(i))));
//				}else{
//					cell.setCellValue(objToString(dataMap.get(fieldList.get(i))));
//				}
//			}
//		}
		wb.write(fileOut);
		fileOut.close();
			if(targetFile1.exists())
			{
				usegetResponse().setHeader("Server","www.tjtt.com");
				usegetResponse().setHeader("Content-Type", "application/octet-stream");
				usegetResponse().setHeader("Content-Length", String.valueOf(targetFile1.length()));
	
				usegetResponse().setHeader("Content-Disposition", "attachment; filename=\"" + java.net.URLEncoder.encode(excel_name,"UTF-8").replace( "+",   "%20")  + "\"");	
				try {
					OutputStream downloadStream=usegetResponse().getOutputStream();
					FileInputStream fin=new 	FileInputStream(targetFile1);
					byte[] b=new byte[1024];	
	
			
					int length=fin.read(b);
					while(length>0)
					{
						downloadStream.write(b,0,length);
						length=fin.read(b);
					}
					downloadStream.flush();
					fin.close();	
					//addMessage("下载成功！");
				} catch (IOException e) {
					e.printStackTrace();
				}			
			}	
	}
	public static void createExcel20073(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList,String userName,Date createTime)
			throws Exception {
		XSSFWorkbook wb = new XSSFWorkbook();
		String[] title = { "通讯录编号", "手机串号", "联系人姓名", "联系人电话", "联系人邮箱", "创建日期","公司名称" };
		//String targetName = "AutoAddressList.xlsx";
		//String filePath = "export/" + targetName;
		String filePath = "c:/cf/export/"+PubMethod.GetTimerName()+"/";
		//filePath = ServletActionContext.getServletContext().getRealPath(
			//	filePath);
		File targetFile = new File(filePath);
		if ( ! (targetFile.exists())  &&   ! (targetFile.isDirectory()))  {
            boolean  creadok  =  targetFile.mkdirs();
            if (creadok)  {
               System.out.println( " ok:创建文件夹成功！ " );
           } else  {
               System.out.println( " err:创建文件夹失败！ " );                    
           } 
       } 
		//filePath = filePath +excel_name;
		filePath = filePath + excel_name;
		File targetFile1 = new File(filePath);
		if (targetFile1.exists()) {
			targetFile1.delete();
		} else {
			targetFile1.createNewFile();
		}
		OutputStream os = new FileOutputStream(targetFile1);
		XSSFSheet sheet = PoiExcelUtil.createSheet(wb, "通讯录列表");
		PoiExcelUtil.mergeCell(sheet, 0, 0, 0, title.length - 1);
		XSSFRow row0 = PoiExcelUtil.createRow(sheet, 0, 1200);
		XSSFFont font0 = (XSSFFont) PoiExcelUtil.createFont(wb,
				XSSFFont.BOLDWEIGHT_BOLD, IndexedColors.BLACK.getIndex(),
				(short) 24);
		XSSFCellStyle cellStyle = (XSSFCellStyle) PoiExcelUtil
				.createBorderCellStyle(wb, XSSFCellStyle.ALIGN_CENTER,
						IndexedColors.WHITE.getIndex(), IndexedColors.WHITE
								.getIndex(), font0);
		PoiExcelUtil.createCell(row0, 0, cellStyle).setCellValue("通讯录列表");
		
		// 设置标题
		XSSFRow row1 = PoiExcelUtil.createRow(sheet, 1, 600);
		XSSFFont font1 = (XSSFFont) PoiExcelUtil.createFont(wb,
				XSSFFont.BOLDWEIGHT_NORMAL, IndexedColors.BLACK.getIndex(),
				(short) 14);
		XSSFCellStyle cellStyle1 = (XSSFCellStyle) PoiExcelUtil
				.createBorderCellStyle(wb, XSSFCellStyle.ALIGN_CENTER,
						IndexedColors.WHITE.getIndex(), IndexedColors.WHITE
								.getIndex(), font1);
		//for (int i = 0; i < title.length; i++) {
		//	XSSFCell cell = PoiExcelUtil.createCell(row1, i, cellStyle1);
		//	cell.setCellValue(title[i]);
		//s}
		// ===============================================================
		for (int i = 0; i < headList.size(); i++) {

			// 在索引0的位置创建单元格（左上端）
			XSSFCell cell = row1.createCell(i);
			// 定义单元格为字符串类型
			cell.setCellType(XSSFCell.CELL_TYPE_STRING);
			//cell.setCellType(XSSFCell.ENCODING_UTF_16);
			//cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
			// 在单元格中输入一些内容
			// String aa =  new String ( headList.get(i).getBytes("ISO-8859-1"),"UTF-8");
			// String bb =  new String ( headList.get(i).getBytes("ISO-8859-1"),"GBK");
			// String cc =  new String ( headList.get(i).getBytes("ISO-8859-1"),"gb2312");
			 
			 
			cell.setCellValue(headList.get(i));
		}
		XSSFFont fontI = (XSSFFont) PoiExcelUtil.createFont(wb,
				XSSFFont.BOLDWEIGHT_NORMAL, IndexedColors.BLACK.getIndex(),
				(short) 12);
		XSSFCellStyle cellStyleI = (XSSFCellStyle) PoiExcelUtil
				.createBorderCellStyle(wb, XSSFCellStyle.ALIGN_CENTER,
						IndexedColors.WHITE.getIndex(), IndexedColors.WHITE
								.getIndex(), fontI);
		// 填充表格
		String str1;
		for (int n = 0; n < dataList.size(); n++) {
			// 在索引1的位置创建行（最顶端的行）
			XSSFRow row_value = sheet.createRow(n + 1);
			Map<String, Object> dataMap = dataList.get(n);
			// ===============================================================
			
			for (int i = 0; i < fieldList.size(); i++) {

				// 在索引0的位置创建单元格（左上端）
				XSSFCell cell = row_value.createCell(i);
				// 定义单元格为字符串类型
				cell.setCellType(XSSFCell.CELL_TYPE_STRING);
				// 在单元格中输入一些内容
				str1=objToString(dataMap.get(fieldList.get(i)));
				if(DataTypeJudge(fieldList.get(i))){
					cell.setCellValue(DataTypeToCN(fieldList.get(i),dataMap.get(fieldList.get(i))));
					
//					sheet.addMergedRegion(new Region(i,(short)1,i,(short)2));// 四个参数分别是：起始行，起始列，结束行，结束列   

				}else{
					cell.setCellValue(objToString(dataMap.get(fieldList.get(i))));
				}
				
			}
			// ===============================================================
		}
		sheet.setColumnWidth(3, 20 * 256);
		sheet.setColumnWidth(4, 40 * 256);
		sheet.setColumnWidth(5, 20 * 256);
		sheet.setColumnWidth(6, 50 * 256);
		wb.write(os);
		os.close();
		downLoad(filePath, targetFile1, excel_name);
	}
	//下载
	public static  void downLoad(String realPath, File file, String fileName) throws UnsupportedEncodingException {
		HttpServletResponse response = usegetResponse(); 
		response.setHeader("Server","www.tjtt.com");
		response.setHeader("Content-Type", "application/octet-stream");
		response.setHeader("Content-Length", String.valueOf(file.length()));

		response.setHeader("Content-Disposition", "attachment; filename=\"" + java.net.URLEncoder.encode(fileName,"UTF-8").replace( "+",   "%20")  + "\"");	
		
		try {
			OutputStream downloadStream=response.getOutputStream();
			FileInputStream fin=new FileInputStream(file);
			byte[] b=new byte[1024];				
			int length=fin.read(b);
			while(length>0)
			{
				downloadStream.write(b,0,length);
				length=fin.read(b);
			}
			downloadStream.flush();
			fin.close();	
		} catch (IOException e) {
			e.printStackTrace();
		}
	 
	}
	public static void createExcel20071(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList,String userName,Date createTime)
			throws Exception {
		

		// 创建新的Excel 工作簿
		XSSFWorkbook workbook = new XSSFWorkbook();
		// 在Excel工作簿中建一工作表，其名为缺省值
		// 如要新建一名为"效益指标"的工作表，其语句为：
		// HSSFSheet sheet = workbook.createSheet("效益指标");
		XSSFSheet sheet = workbook.createSheet();
//---------------add--------- start1---------------------------------------------------------------------------------------
		// 设置字体     
		XSSFFont font = workbook.createFont();     
	    font.setFontName("黑体");     
	    font.setFontHeightInPoints((short) 10);  
	    font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);// 加粗  
	    
		XSSFFont headfont = workbook.createFont();     
	    headfont.setFontName("黑体");     
	    headfont.setFontHeightInPoints((short) 22);// 字体大小     
	    headfont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);// 加粗     
	    
		// 另一个样式     
		XSSFCellStyle headstyle = workbook.createCellStyle();     
		headstyle.setFont(headfont);     
	    headstyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);// 左右居中     
	    headstyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);// 上下居中     
	    headstyle.setLocked(true);     
	    headstyle.setWrapText(true);// 自动换行   
	    
	    // 另一个样式     
		XSSFCellStyle centerstyle = workbook.createCellStyle();     
		centerstyle.setFont(font);     
		//centerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
		centerstyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);// 上下居中     
		centerstyle.setWrapText(false);     
		centerstyle.setLeftBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderLeft((short) 1);     
		centerstyle.setRightBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderRight((short) 1);     
		//centerstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 设置单元格的边框为粗体     
		centerstyle.setBottomBorderColor(HSSFColor.BLACK.index); // 设置单元格的边框颜色．     
		centerstyle.setFillForegroundColor(HSSFColor.WHITE.index);// 设置单元格的背景颜色．  
	
/*        第二个sheet
		HSSFRow row0 = sheet.createRow(0);   //第二个sheet的第一行  
		// 设置行高     
        row0.setHeight((short) 900);     
        // 创建第一列     
        HSSFCell cell0 = row0.createCell(0);     
        cell0.setCellValue(new HSSFRichTextString(excel_name.substring(0,(excel_name.lastIndexOf(".")))));     
        cell0.setCellStyle(headstyle);     
        *//**   
         * 合并单元格   
         *    第一个参数：第一个单元格的行数（从0开始）   
         *    第二个参数：第二个单元格的行数（从0开始）   
         *    第三个参数：第一个单元格的列数（从0开始）   
         *    第四个参数：第二个单元格的列数（从0开始）   
         *//*     
        CellRangeAddress range = new CellRangeAddress(0, 0, 0, 7);     
        sheet.addMergedRegion(range);     
        // 创建第二行     
		HSSFRow row1 = sheet.createRow(1);     
		HSSFCell cell1 = row1.createCell(0); 
		
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd "); 
		String jointime = sdf.format(createTime);
		
		cell1.setCellValue("导出时间："+jointime);     
		cell1.setCellStyle(centerstyle);  
		// 第三行     
        HSSFRow row2 = sheet.createRow(2);     
        HSSFCell cell3 = row2.createCell(0);     
        cell3.setCellValue("导出人："+userName);     
        cell3.setCellStyle(centerstyle);     
		// 第4行     
        HSSFRow row3 = sheet.createRow(3);     
        HSSFCell cell2 = row3.createCell(0);     
        cell2.setCellValue("总条数："+dataList.size());     
        cell2.setCellStyle(centerstyle);    */ 
//---------------add---start2---------------------------------------------------------------------------------------------		
		
//--------------add----end-----------------------------------------------------------------------------------------------		
		// 在索引0的位置创建行（最顶端的行）
		XSSFRow row = sheet.createRow(0);
		// ===============================================================
		for (int i = 0; i < headList.size(); i++) {

			// 在索引0的位置创建单元格（左上端）
			XSSFCell cell = row.createCell(i);
			// 定义单元格为字符串类型
			cell.setCellType(XSSFCell.CELL_TYPE_STRING);
			//cell.setCellType(XSSFCell.ENCODING_UTF_16);
			//cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
			// 在单元格中输入一些内容
			// String aa =  new String ( headList.get(i).getBytes("ISO-8859-1"),"UTF-8");
			// String bb =  new String ( headList.get(i).getBytes("ISO-8859-1"),"GBK");
			// String cc =  new String ( headList.get(i).getBytes("ISO-8859-1"),"gb2312");
			 
			 
			cell.setCellValue(headList.get(i));
		}
		// ===============================================================
		String str1;
		for (int n = 0; n < dataList.size(); n++) {
			// 在索引1的位置创建行（最顶端的行）
			XSSFRow row_value = sheet.createRow(n + 1);
			Map<String, Object> dataMap = dataList.get(n);
			// ===============================================================
			
			for (int i = 0; i < fieldList.size(); i++) {

				// 在索引0的位置创建单元格（左上端）
				XSSFCell cell = row_value.createCell(i);
				// 定义单元格为字符串类型
				cell.setCellType(XSSFCell.CELL_TYPE_STRING);
				// 在单元格中输入一些内容
				str1=objToString(dataMap.get(fieldList.get(i)));
				if(DataTypeJudge(fieldList.get(i))){
					cell.setCellValue(DataTypeToCN(fieldList.get(i),dataMap.get(fieldList.get(i))));
					
//					sheet.addMergedRegion(new Region(i,(short)1,i,(short)2));// 四个参数分别是：起始行，起始列，结束行，结束列   

				}else{
					cell.setCellValue(objToString(dataMap.get(fieldList.get(i))));
				}
				
			}
			// ===============================================================
		}
		/**
		FileOutputStream fileOut = new FileOutputStream("c:/123.xls");
		workbook.write(fileOut);
        fileOut.close();
        */
		OutputStream output=null;
		//usegetResponse().setContentType("application/octet-stream;charset=UTF-8");
		usegetResponse().setHeader("Content-Type", "application/octet-stream");
		usegetResponse().setContentType("application/ms-excel;charset=UTF-8");// // 指定文件的保存类型。
		usegetResponse().setCharacterEncoding("UTF-8");
		
		usegetResponse().addHeader("Content-Disposition", "attachment;filename="
    		     + getDownloadChineseFileName(excel_name));
        output = usegetResponse().getOutputStream();
        workbook.write(output);
        output.flush();
        output.close();
	}
	public static void createExcel20072(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList,String userName,Date createTime)
			throws Exception {
		

		// 创建新的Excel 工作簿
		XSSFWorkbook workbook = new XSSFWorkbook();
		 
		String path = "c:/cf/export/"+PubMethod.GetTimerName()+"/";
	
		
		File file = new File(path);
		if ( ! (file.exists())  &&   ! (file.isDirectory()))  {
             boolean  creadok  =  file.mkdirs();
             if (creadok)  {
                System.out.println( " ok:创建文件夹成功！ " );
            } else  {
                System.out.println( " err:创建文件夹失败！ " );                    
            } 
        } 
		path = path +excel_name;
		FileOutputStream fileOut = new FileOutputStream(path);
		workbook.write(fileOut);
		
//		if(file.exists()){
//			InputStream ins=new FileInputStream(path);//构造一个读取文件的IO流对象
//			BufferedInputStream bins=new BufferedInputStream(ins);//放到缓冲流里面
//			OutputStream outs=usegetResponse().getOutputStream();//获取文件输出IO流
//			BufferedOutputStream bouts=new BufferedOutputStream(outs);
//			outs = usegetResponse().getOutputStream();
//			usegetResponse().setContentType("application/x-download");//设置response内容的类型
//			usegetResponse().setHeader("Content-disposition","attachment;filename="+ URLEncoder.encode(excel_name, "UTF-8"));//设置头部信息
//			int bytesRead = 0;
//			byte[] buffer = new byte[8192];
//			//开始向网络传输文件流
//			while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
//				bouts.write(buffer, 0, bytesRead);
//			}
//			bouts.flush();//这里一定要调用flush()方法
//			ins.close();
//			bins.close();
//			outs.close();
//			fileOut.close();
//		}else{
//			System.out.println("下载的文件不存在");
//		}
		if(file.exists()){
			InputStream ins=new FileInputStream(path);//构造一个读取文件的IO流对象
			BufferedInputStream bins=new BufferedInputStream(ins);//放到缓冲流里面
			//OutputStream outs=usegetResponse().getOutputStream();//获取文件输出IO流
			BufferedOutputStream bouts=new BufferedOutputStream(fileOut);
			usegetResponse().setContentType("application/x-download");//设置response内容的类型
			usegetResponse().setHeader("Content-disposition","attachment;filename="+ URLEncoder.encode(path, "UTF-8"));//设置头部信息
			int bytesRead = 0;
			byte[] buffer = new byte[8192];
			//开始向网络传输文件流
			while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
				bouts.write(buffer, 0, bytesRead);
			}
			bouts.flush();//这里一定要调用flush()方法
			ins.close();
			bins.close();
		//	outs.close();
			bouts.close();
		}else{
			System.out.println("下载的文件不存在");
		}
       // fileOut.close();
       
       /** OutputStream output=null;
		usegetResponse().setHeader("Content-Type", "application/octet-stream");
		usegetResponse().addHeader("Content-Disposition", "attachment;filename="
    		     + getDownloadChineseFileName(excel_name));
        output = usegetResponse().getOutputStream();
        workbook.write(output);
        output.flush();
        output.close(); */
	}
	public static void createTZExcel(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList,String userName,Date createTime)
			throws Exception {
		// 创建新的Excel 工作簿
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 在Excel工作簿中建一工作表，其名为缺省值
		// 如要新建一名为"效益指标"的工作表，其语句为：
		// HSSFSheet sheet = workbook.createSheet("效益指标");
		HSSFSheet sheet = workbook.createSheet();
//---------------add--------- start1---------------------------------------------------------------------------------------
		// 设置字体     
		HSSFFont font = workbook.createFont();     
	    font.setFontName("黑体");     
	    font.setFontHeightInPoints((short) 10);  
	    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗  
	    
		HSSFFont headfont = workbook.createFont();     
	    headfont.setFontName("黑体");     
	    headfont.setFontHeightInPoints((short) 22);// 字体大小     
	    headfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗     
	    
		// 另一个样式     
		HSSFCellStyle headstyle = workbook.createCellStyle();     
		headstyle.setFont(headfont);     
	    headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
	    headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中     
	    headstyle.setLocked(true);     
	    headstyle.setWrapText(true);// 自动换行   
	    
	    // 另一个样式     
		HSSFCellStyle centerstyle = workbook.createCellStyle();     
		centerstyle.setFont(font);     
		//centerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
		centerstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中     
		centerstyle.setWrapText(false);     
		centerstyle.setLeftBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderLeft((short) 1);     
		centerstyle.setRightBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderRight((short) 1);     
		//centerstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 设置单元格的边框为粗体     
		centerstyle.setBottomBorderColor(HSSFColor.BLACK.index); // 设置单元格的边框颜色．     
		centerstyle.setFillForegroundColor(HSSFColor.WHITE.index);// 设置单元格的背景颜色．  
	
        /*第二个sheet*/
		HSSFRow row0 = sheet.createRow(0);   //第二个sheet的第一行  
		// 设置行高     
        row0.setHeight((short) 900);     
        // 创建第一列     
        HSSFCell cell0 = row0.createCell(0);     
        cell0.setCellValue(new HSSFRichTextString(excel_name.substring(0,(excel_name.lastIndexOf(".")))));     
        cell0.setCellStyle(headstyle);     
        /**   
         * 合并单元格   
         *    第一个参数：第一个单元格的行数（从0开始）   
         *    第二个参数：第二个单元格的行数（从0开始）   
         *    第三个参数：第一个单元格的列数（从0开始）   
         *    第四个参数：第二个单元格的列数（从0开始）   
         */     
        CellRangeAddress range = new CellRangeAddress(0, 0, 0, 7);     
        sheet.addMergedRegion(range);     
        
//---------------add---start2---------------------------------------------------------------------------------------------		
		
//--------------add----end-----------------------------------------------------------------------------------------------		
		// 在索引0的位置创建行（最顶端的行）
		HSSFRow row = sheet.createRow(1);
		// ===============================================================
		for (int i = 0; i < headList.size(); i++) {

			// 在索引0的位置创建单元格（左上端）
			HSSFCell cell = row.createCell(i);
			// 定义单元格为字符串类型
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			// 在单元格中输入一些内容
			cell.setCellValue(headList.get(i));
		}
		// ===============================================================
		String str1;
		for (int n = 0; n < dataList.size(); n++) {
			// 在索引1的位置创建行（最顶端的行）
			HSSFRow row_value = sheet.createRow(n + 2);
			Map<String, Object> dataMap = dataList.get(n);
			// ===============================================================
			
			for (int i = 0; i < fieldList.size(); i++) {

				// 在索引0的位置创建单元格（左上端）
				HSSFCell cell = row_value.createCell(i);
				// 定义单元格为字符串类型
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				// 在单元格中输入一些内容
				str1=objToString(dataMap.get(fieldList.get(i)));
				if(DataTypeJudge(fieldList.get(i))){
					cell.setCellValue(DataTypeToCN(fieldList.get(i),dataMap.get(fieldList.get(i))));
					
//					sheet.addMergedRegion(new Region(i,(short)1,i,(short)2));// 四个参数分别是：起始行，起始列，结束行，结束列   

				}else{
					cell.setCellValue(objToString(dataMap.get(fieldList.get(i))));
				}
				
			}
			// ===============================================================
		}
		
		FileOutputStream fileOut = new FileOutputStream("c:/123.xls");
		workbook.write(fileOut);
        fileOut.close();
        
		/*OutputStream output=null;
		usegetResponse().setHeader("Content-Type", "application/octet-stream");
		usegetResponse().addHeader("Content-Disposition", "attachment;filename="
    		     + getDownloadChineseFileName(excel_name));
        output = usegetResponse().getOutputStream();
        workbook.write(output);
        output.flush();
        output.close();*/
	}
	//导出excel
	public static void createExcelBase(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList,String userName,Date createTime)
			throws Exception {
		// 创建新的Excel 工作簿
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 在Excel工作簿中建一工作表，其名为缺省值
		// 如要新建一名为"效益指标"的工作表，其语句为：
		// HSSFSheet sheet = workbook.createSheet("效益指标");
		HSSFSheet sheet = workbook.createSheet();
//---------------add--------- start1---------------------------------------------------------------------------------------
		// 设置字体     
		HSSFFont font = workbook.createFont();     
	    font.setFontName("黑体");     
	    font.setFontHeightInPoints((short) 10);  
	    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗  
	    
		HSSFFont headfont = workbook.createFont();     
	    headfont.setFontName("黑体");     
	    headfont.setFontHeightInPoints((short) 22);// 字体大小     
	    headfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗     
	    
		// 另一个样式     
		HSSFCellStyle headstyle = workbook.createCellStyle();     
		headstyle.setFont(headfont);     
	    headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
	    headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中     
	    headstyle.setLocked(true);     
	    headstyle.setWrapText(true);// 自动换行   
	    
	    // 另一个样式     
		HSSFCellStyle centerstyle = workbook.createCellStyle();     
		centerstyle.setFont(font);     
		//centerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中     
		centerstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中     
		centerstyle.setWrapText(false);     
		centerstyle.setLeftBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderLeft((short) 1);     
		centerstyle.setRightBorderColor(HSSFColor.BLACK.index);     
		centerstyle.setBorderRight((short) 1);     
		//centerstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 设置单元格的边框为粗体     
		centerstyle.setBottomBorderColor(HSSFColor.BLACK.index); // 设置单元格的边框颜色．     
		centerstyle.setFillForegroundColor(HSSFColor.WHITE.index);// 设置单元格的背景颜色．   
 		// 在索引0的位置创建行（最顶端的行）
		HSSFRow row = sheet.createRow(0);
		// ===============================================================
		for (int i = 0; i < headList.size(); i++) {
			// 在索引0的位置创建单元格（左上端）
			HSSFCell cell = row.createCell(i);
			// 定义单元格为字符串类型
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			// 在单元格中输入一些内容
			cell.setCellValue(headList.get(i));
		}
		// ===============================================================
		String str1;
		for (int n = 0; n < dataList.size(); n++) {
			// 在索引1的位置创建行（最顶端的行）
			HSSFRow row_value = sheet.createRow(n + 1);
			Map<String, Object> dataMap = dataList.get(n);
			// ===============================================================
			for (int i = 0; i < fieldList.size(); i++) {
				// 在索引0的位置创建单元格（左上端）
				HSSFCell cell = row_value.createCell(i);
				// 定义单元格为字符串类型
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				// 在单元格中输入一些内容
				str1=objToString(dataMap.get(fieldList.get(i)));
				if(DataTypeJudge(fieldList.get(i))){
					cell.setCellValue(DataTypeToCN(fieldList.get(i),dataMap.get(fieldList.get(i))));
				}else{
					cell.setCellValue(objToString(dataMap.get(fieldList.get(i))));
				}
			}
		}
		
		OutputStream output=null;
		usegetResponse().setHeader("Content-Type", "application/octet-stream");
		usegetResponse().addHeader("Content-Disposition", "attachment;filename="
    		     + getDownloadChineseFileName(excel_name));
        output = usegetResponse().getOutputStream();
        workbook.write(output);
        output.flush();
        output.close();
	}
	
	public static String getDownloadChineseFileName(String file_name) {
		String downloadChineseFileName = file_name;
		try {
			downloadChineseFileName = new String(downloadChineseFileName
			.getBytes(), "ISO-8859-1");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return downloadChineseFileName;
	}
	
	private static String objToString(Object obj) {
		if (obj == null) {
			return "";
		} else {
			if (obj instanceof String) {
				return (String) obj;
			} else if (obj instanceof Date) {
				//return dateToString();
				SimpleDateFormat stf=new SimpleDateFormat("yyyy-MM-dd");
				String str=stf.format(obj);
				return str;
				//return null;// DateUtil.dateToString((Date)
				// obj,DateUtil.DATESTYLE_SHORT_EX);
			} else {
				return obj.toString();
			}
		}
	}
	
	/***
	 * 判断业务状态进行输出控制
	 * @return
	 */
	private static String DataTypeToCN(Object obj1,Object obj2) {
		/*if(obj1.toString().equals("STATE")){
			if(obj2.toString().equals("0")){
				return "aaaaaa";
			}else if(obj2.toString().equals("1")){
				return "bbbb";
			}else{
				return "acbdfweerfqwe";	
			}
		}else if(obj1.toString().equals("OVERDATE")){
			return obj2.toString().split("-")[1]+"月";
			
		}else{*/
			return obj1.toString();
//		}
		
	}
	/***
	 * 判断此字段数据是否值得进行逻辑值的转换
	 * @param obj
	 * @return
	 */
	private static Boolean DataTypeJudge(Object obj) {
		/*if(obj.toString().equals("STATE")){
			return true;
		}else if(obj.toString().equals("OVERDATE")){
			return true;
		}else{
			
		}*/return false;
	}
	
	/***
	 * 样式
	 * 
	 * @return
	 */
	private static void setStyle(HSSFWorkbook workbook){
	  HSSFCellStyle normalStyle = workbook.createCellStyle();
	  normalStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
	  normalStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
	  normalStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
	  normalStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
	  normalStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
	  normalStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
	  normalStyle.setWrapText(true);
	
	}
	public static HttpServletResponse usegetResponse(){
		return ServletActionContext.getResponse();
	}
	
    
    /**
	 * 导出excel
	 */
	public void exportlhExcel(String fileName,List<String> headCNlist,List<String> fieldlistChoose,List<String> fieldlistAboutDB,Map filterMap,List setListForExcel,String userName,Date createTime){
		ExcelExportUtil exExcelUtil = new ExcelExportUtil();
		List<Map<String, Object>> dataList = getDataList(fieldlistAboutDB,filterMap,setListForExcel);
		List<String> headList = headCNlist;
		List<String> fieldList = fieldlistChoose;

		try {
			exExcelUtil.createExcel2007(fileName, headList, fieldList,dataList,userName,createTime);
			//exExcelUtil.createExcel(fileName, headList, fieldList,dataList,userName,createTime);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}	
	/**
	 * 导出两个sheet的excel
	 */
	public void exportlhExcel2(String fileName,List<String> headCNlist,List<String> fieldlistChoose,List<String> fieldlistAboutDB,Map filterMap,List setListForExcel,String userName,Date createTime,List<String> fieldlistChoose2,List<String> fieldlistAboutDB2,List setList,String headName){
		ExcelExportUtil exExcelUtil = new ExcelExportUtil();
		List<Map<String, Object>> dataList = getDataList(fieldlistAboutDB,filterMap,setListForExcel);
		List<Map<String, Object>> dataList0 = getDataList(fieldlistAboutDB2,filterMap,setList);
		List<String> headList = headCNlist;
		List<String> fieldList = fieldlistChoose;
		List<String> fieldList2 = fieldlistChoose2;
		

		try {
			exExcelUtil.createExcel1(fileName, headList, fieldList,dataList,userName,createTime,fieldList2,dataList0,headName);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	 /**
	 * 导出台账excel
	 */
	public void exportTZExcel(String fileName,List<String> headCNlist,List<String> fieldlistChoose,List<String> fieldlistAboutDB,Map filterMap,List setListForExcel,String userName,Date createTime){
		ExcelExportUtil exExcelUtil = new ExcelExportUtil();
		List<Map<String, Object>> dataList = getDataList(fieldlistAboutDB,filterMap,setListForExcel);
		List<String> headList = headCNlist;
		List<String> fieldList = fieldlistChoose;

		try {
			exExcelUtil.createTZExcel(fileName, headList, fieldList,dataList,userName,createTime);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void exportJstjExcel(String fileName,List<String> headCNlist,List<String> fieldlistChoose,List<String> fieldlistAboutDB,Map filterMap,List setListForExcel,String userName,Date createTime){
		ExcelExportUtil exExcelUtil = new ExcelExportUtil();
		List<Map<String, Object>> dataList = getDataList(fieldlistAboutDB,filterMap,setListForExcel);
		List<String> headList = headCNlist;
		List<String> fieldList = fieldlistChoose;

		try {
			exExcelUtil.createTZExcel(fileName, headList, fieldList,dataList,userName,createTime);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public Map<String, String> getMapDataList(List<String> fieldlist,List<String> titlelist) {
		/**
		 * 匹配前台名称和前台字段
		 */
		Map<String, String> map = new HashMap<String, String>();
		try {
		
//			String[] fl = new String[fieldlist.size()];
//			String[] tl = new String[titlelist.size()];
			if(fieldlist.size()==titlelist.size()){
				for(int j=0;j<fieldlist.size();j++){
					map.put((String)fieldlist.get(j),(String)titlelist.get(j));
				}
			}
			
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return map;
	}
	/**
	 * 输出excel的中文字段名称
	 * param1输出字段param2所有字段关联的中文
	 */
	public List<String> getTitleDataList(List<String> fieldlist,Map<String,String> titlelist) {
		
			List<String> list = new ArrayList<String>();
			try {
				
//				String[] fl = new String[fieldlist.size()];
//				Map<String, String> map = new HashMap<String, String>();
				for(int j=0,i=0;j<titlelist.size()&&i<fieldlist.size();j++,i++){
					String s = (String)titlelist.get(fieldlist.get(i));
					list.add(s);
				}
				
			} catch (RuntimeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return list;
		}

	private List<Map<String, Object>> getDataList(List<String> fieldlist,Map filterMap,List setListForExcel) {
		/**
		 * 数据集合
		 */
		List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
		List<?> list = new ArrayList(); 
		list =setListForExcel;
		String[] st = new String[fieldlist.size()];
		Object[] obj = new Object[list.size()];
		for(int j=0;j<list.size();j++){
			Map<String, Object> map = new HashMap<String, Object>();
			obj = (Object[])list.get(j);
//			System.out.print(obj);
			for(int i=0;i<fieldlist.size();i++){
				map.put((String)fieldlist.get(i),obj[i]);
			}
			dataList.add(j,map);
			
		}
		return dataList;
	}
	/**
	 * 导出excel
	 */
	public void exportlhExcel3(String fileName,List<String> headCNlist,List<String> fieldlistChoose,List<String> fieldlistAboutDB,Map filterMap,List setListForExcel){
		ExcelExportUtil exExcelUtil = new ExcelExportUtil();
		List<Map<String, Object>> dataList = getDataList(fieldlistAboutDB,filterMap,setListForExcel);
		List<String> headList = headCNlist;
		List<String> fieldList = fieldlistChoose;
		try {
			exExcelUtil.createExcel(fileName, headList, fieldList,dataList);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 导出excel
	 */
	public void exportlhExcel4(String fileName,List<String> headCNlist,List<String> fieldlistChoose,List<String> fieldlistAboutDB,Map filterMap,List setListForExcel){
		ExcelExportUtil exExcelUtil = new ExcelExportUtil();
		List<Map<String, Object>> dataList = getDataList(fieldlistAboutDB,filterMap,setListForExcel);
		List<String> headList = headCNlist;
		List<String> fieldList = fieldlistChoose;

		try {
			exExcelUtil.createExcel2(fileName, headList, fieldList,dataList);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * @param excel_name
	 *            生成的Excel文件路径+名称
	 * @param headList
	 *            Excel文件Head标题集合
	 * @param field_list
	 *            Excel文件Field标题集合
	 * @param dataList
	 *            Excel文件数据内容部分
	 * @throws Exception
	 */
	public static void createExcel(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList)
			throws Exception {
		// 创建新的Excel 工作簿
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 在Excel工作簿中建一工作表，其名为缺省值
		// 如要新建一名为"效益指标"的工作表，其语句为：
		// HSSFSheet sheet = workbook.createSheet("效益指标");
		HSSFSheet sheet = workbook.createSheet();
		// 在索引0的位置创建行（最顶端的行）
		HSSFRow row = sheet.createRow(0);
		// ===============================================================
		for (int i = 0; i < headList.size(); i++) {

			// 在索引0的位置创建单元格（左上端）
			HSSFCell cell = row.createCell(i);
			// 定义单元格为字符串类型
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			// 在单元格中输入一些内容
			cell.setCellValue(headList.get(i));
		}
		// ===============================================================
		String str;
		for (int n = 0; n < dataList.size(); n++) {
			// 在索引1的位置创建行（最顶端的行）
			HSSFRow row_value = sheet.createRow(n + 1);
			Map<String, Object> dataMap = dataList.get(n);
			// ===============================================================
			for (int i = 0; i < fieldList.size(); i++) {

				// 在索引0的位置创建单元格（左上端）
				HSSFCell cell = row_value.createCell(i);
				// 定义单元格为字符串类型
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				// 在单元格中输入一些内容
				str=objToString(dataMap.get(fieldList.get(i)));
				if(DataTypeJudge(fieldList.get(i))){
					cell.setCellValue(DataTypeToCN(fieldList.get(i),dataMap.get(fieldList.get(i))));
					
//					sheet.addMergedRegion(new Region(i,(short)1,i,(short)2));// 四个参数分别是：起始行，起始列，结束行，结束列   

				}else{
					cell.setCellValue(objToString(dataMap.get(fieldList.get(i))));
				}
				
			}
			// ===============================================================
			
		}
		OutputStream output=null;
		usegetResponse().setHeader("Content-Type", "application/octet-stream");
		usegetResponse().addHeader("Content-Disposition", "attachment;filename="
    		     + getDownloadChineseFileName(excel_name));
        output = usegetResponse().getOutputStream();
        workbook.write(output);
        output.flush();
        output.close();
	}
	/**
	 * @param excel_name
	 *            生成的Excel文件路径+名称
	 * @param headList
	 *            Excel文件Head标题集合
	 * @param field_list
	 *            Excel文件Field标题集合
	 * @param dataList
	 *            Excel文件数据内容部分
	 * @throws Exception
	 */
	public static void createExcel2(String excel_name, List<String> headList,
			List<String> fieldList, List<Map<String, Object>> dataList)
			throws Exception {
		// 创建新的Excel 工作簿
		HSSFWorkbook workbook = new HSSFWorkbook();
		// 在Excel工作簿中建一工作表，其名为缺省值
		// 如要新建一名为"效益指标"的工作表，其语句为：
		// HSSFSheet sheet = workbook.createSheet("效益指标");
		HSSFSheet sheet = workbook.createSheet();
		// 在索引0的位置创建行（最顶端的行）
		HSSFRow row = sheet.createRow(0);
		// ===============================================================
		
		for (int i = 0; i < headList.size()+5; i++) {
			// 在索引0的位置创建单元格（左上端）
			HSSFCell cell = row.createCell(i);
			// 定义单元格为字符串类型
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            if(i<headList.size()){//action传过来的中文字段名称
				// 在单元格中输入一些内容
				cell.setCellValue(headList.get(i));
            }else{//需要新增加的中文字段名
            	if(i == headList.size()){
            		cell.setCellValue("实际维保时间");
            	}else if(i == headList.size()+1){
            		cell.setCellValue("实施部门/人员");
            	}else if(i == headList.size()+2){
            		cell.setCellValue("保养过程记录");
            	}else if(i == headList.size()+3){
            		cell.setCellValue("效果确认");
            	}else if(i == headList.size()+4){
            		cell.setCellValue("确认人");
            	}
            }
			
		}
		// ===============================================================
		String str;
		for (int n = 0; n < dataList.size(); n++) {
			// 在索引1的位置创建行（最顶端的行）
			HSSFRow row_value = sheet.createRow(n + 1);
			Map<String, Object> dataMap = dataList.get(n);
			// ===============================================================
			
			for (int i = 0; i < fieldList.size(); i++) {

				// 在索引0的位置创建单元格（左上端）
				HSSFCell cell = row_value.createCell(i);
				// 定义单元格为字符串类型
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				// 在单元格中输入一些内容
				str=objToString(dataMap.get(fieldList.get(i)));
				if(DataTypeJudge(fieldList.get(i))){
					cell.setCellValue(DataTypeToCN(fieldList.get(i),dataMap.get(fieldList.get(i))));
					
//					sheet.addMergedRegion(new Region(i,(short)1,i,(short)2));// 四个参数分别是：起始行，起始列，结束行，结束列   

				}else{
					cell.setCellValue(objToString(dataMap.get(fieldList.get(i))));
				}
				
			}
			// ===============================================================
		}
		OutputStream output=null;
		usegetResponse().setHeader("Content-Type", "application/octet-stream");
		usegetResponse().addHeader("Content-Disposition", "attachment;filename="
    		     + getDownloadChineseFileName(excel_name));
        output = usegetResponse().getOutputStream();
        workbook.write(output);
        output.flush();
        output.close();
	}
	
	
}
